package com.jelly.config.thymeleaf;

import com.jelly.common.constant.Constant;
import com.jelly.common.enums.WebsiteDetailsType;
import com.jelly.common.util.bean.SpringUtil;
import com.jelly.web.modules.basics.websiteDetails.domain.WebsiteDetails;
import com.jelly.web.modules.basics.websiteDetails.service.IWebsiteDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @创建人 ql
 * @创建时间 2018-08-21 11:28
 * @项目名称 jelly
 * @功能描述: 模板参数管理
 **/
public class ThymeleafView {

    /**
     * 设置字典属性
     * @param viewResolver
     */
    @Resource
    public void configureThymeleafStaticVars(ThymeleafViewResolver viewResolver) {
        if(null != viewResolver) {
            Map<String, Object> vars = new HashMap<>();
            WebsiteDetails websiteDetails = SpringUtil.getBean(IWebsiteDetailsService.class).getWebsiteDetails(WebsiteDetailsType.WEBESSEBTIAL.getValue());
            if(null != websiteDetails && Constant.SUCCESS.equals(websiteDetails.getIsState())){
                vars.put("essebtial",websiteDetails.getWebEssential());

            }
            viewResolver.setStaticVariables(vars);
        }
    }

}
